#!/usr/bin/python
# -*- coding:utf-8 -*-
# @author  : micah
# @time    :  
# @function: 
# @version :


from threading import Thread, RLock

num = 0

# 创建一个锁对象
lock_obj = RLock()


def add_():
    global num
    for i in range(1000000):
        # 在计算的过程中我需要保证计算步骤的完整性
        lock_obj.acquire()
        num += i
        lock_obj.release()


def sub_():
    global num
    for i in range(1000000):
        lock_obj.acquire()
        num -= i
        lock_obj.release()


t1 = Thread(target=add_)
t2 = Thread(target=sub_)

t1.start()
t2.start()

t1.join()
t2.join()

print(num)





